var util = require('../../utils/util.js')
var good_at=''//擅长知识领域
var quantity=''//答题数量
var score=''//总成绩
var ranking=''//排名
var newTime=''//获取当前时间
var nickName=''//用户名字
var avatarUrl=''//用户头像
var id = ''//用户id
const app = getApp()
Page({
  data: {
    films: [],
    hasMore: true,
    showLoading: true,
    timedisplay:true,
    start: 0,
    list: {},//答题汇总
    details:[],
  },
  onLoad: function () {
    var that = this;
    //获取用户id
    wx.getStorage({
      key: 'userid',
      success: function (res) {
        that.setData({
          userid: res.data
        })
        console.log(that.data.userid)
        //赋值
        id = that.data.userid
        console.log('=========' + id)
      },
    })
    //获取用户信息
    wx.getUserInfo({
      success: function (res) {
        //console.log(res)
        that.setData({
          nickName: res.userInfo.nickName,
          avatarUrl: res.userInfo.avatarUrl,
        })
        //console.log(that.data.nickName)
        //console.log(that.data.avatarUrl)
      },
    }),
    //获取当前时间
      newTime = util.formatTime(new Date())//获取当前时间
      that.setData({
        newTimes: newTime
      })
    wx.request({
      url: 'http://10.20.58.235:8080/v1/open/question/manager',
      header: {
        'Content-Type': 'application/xml',
      },
      success: function (res) {
        //console.log(res);
        good_at = res.data.area
        that.setData({
          list: res.data,
        })
      }
    }),
    wx.getUserInfo({
      key: '421978594',
      success(res){
        //获取自己的擅长领域
        wx.request({
          url: 'http://10.20.58.235:8080/v1/open/information/manager/area/%7Bid%7D?id=' + id,
          method:'GET',
          success: function (res) {
            good_at = res
            //console.log(good_at);//后天返回关于成绩的数据
            that.setData({
              lists1: good_at.data["0"],
              lists2: good_at.data["1"],
              lists3: good_at.data["2"],
            })
          }
        }),
        //获取答错的数量
        wx.request({
          url: 'http://10.20.58.235:8080/v1/open/information/manager/summary/%7Bid%7D?id=' + id,
          method:'GET',
          success:function(res){
            //console.log(res)
            that.setData({
              list: res.data,
              score: res.data
            })
          }
        }),
        //查看排名
        wx.request({
          url: 'http://10.20.58.235:8080/v1/open/information/manager/Userranking/%7Bid%7D?id=' + id,
          method:'GET',
          success:function(res){
            //console.log(res),
            that.setData({
              ranking:res.data
            })
          }
        })
        //答题情况
        wx.request({
          url: 'http://10.20.58.235:8080/v1/open/information/manager/day/%7Bid%7D?id=' + id,
          method:'GET',
          success:function(res){
          //裁剪字符串
          for (var index in res.data) {
            res.data[index].time = res.data[index].time.substring(0,10);
          }
            that.setData({
              details:res.data
            })
          }
        })
      }
    })
  }
})